package com.example.tnot.Teacher.Homepart.Container;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.example.tnot.R;
import com.example.tnot.Teacher.ActivityConfig.TeacherHomeActivity;
import com.example.tnot.Teacher.Homepart.ItemBean.rv_HomeResourceListItem;
import com.example.tnot.Teacher.Homepart.ItemBean.rv_frequentlyListItem;
import com.example.tnot.Teacher.Homepart.adapter.FrequentlyAdapter;
import com.example.tnot.Teacher.Homepart.adapter.HomeAdapter;

import java.util.ArrayList;
import java.util.List;

public class HomeContainerFragment extends Fragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    View view;
    List<rv_frequentlyListItem> data;
    List<rv_HomeResourceListItem> Recommend;
    RecyclerView rv_frequently;
    GridLayoutManager MyFrequentlayoutManager;
    FrequentlyAdapter MyFrequentadapter;
    RecyclerView rv_recommend;
    HomeAdapter RecommendAdapter;
    private LinearLayout ll_insight,ll_location,ll_ai,ll_down_more;
    private String mParam1;
    private String mParam2;

    public HomeContainerFragment() {
    }
    public static HomeContainerFragment newInstance(String param1, String param2) {
        HomeContainerFragment fragment = new HomeContainerFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }
    @Override
    public void onResume() {
        super.onResume();
        // 确保当前Fragment显示时底部导航栏是可见的
        if (getActivity() instanceof TeacherHomeActivity) {
            ((TeacherHomeActivity) getActivity()).showBottomNavigation();
            ((TeacherHomeActivity) getActivity()).enableViewPagerSwipe();
        }
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.home_container_fragment, container, false);

        InitView();
        InitMyFrequentData();
        setListener();
        //我的常用RecyclerView的配置
        MyFrequentlayoutManager = new GridLayoutManager(getActivity(), 4);
        rv_frequently.setLayoutManager(MyFrequentlayoutManager);
        MyFrequentadapter = new FrequentlyAdapter(data);
        rv_frequently.setAdapter(MyFrequentadapter);

        //推送RecycleView配置
        RecommendAdapter = new HomeAdapter(Recommend);
        rv_recommend.setAdapter(RecommendAdapter);
        rv_recommend.setLayoutManager(new LinearLayoutManager(getActivity()));


//        setupRecyclerView();
        return view;
    }

    private void setListener() {
        ll_insight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_homeContainerFragment_to_insightHomeFragment);
            }
        });
        ll_location.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_homeContainerFragment_to_locationFragment);
            }
        });
        ll_ai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_homeContainerFragment_to_AIHomeFragment);
            }
        });
        ll_down_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
//                navController.navigate(R.id.action_homeContainerFragment_to_downMoreFragment);
            }
        });
    }

    private void InitView() {
        data = new ArrayList();
        Recommend = new ArrayList();
        rv_frequently = view.findViewById(R.id.rv_frequently);
        rv_recommend = view.findViewById(R.id.rv_recommend);
        ll_insight = view.findViewById(R.id.ll_insight);
        ll_location = view.findViewById(R.id.ll_location);
        ll_ai = view.findViewById(R.id.ll_ai);
        ll_down_more = view.findViewById(R.id.ll_down_more);
    }


    private void InitMyFrequentData() {
        data.add(new rv_frequentlyListItem("待批",R.drawable.agent));
        data.add(new rv_frequentlyListItem("云资源",R.drawable.resource));
        data.add(new rv_frequentlyListItem("待办",R.drawable.notmanage));
        data.add(new rv_frequentlyListItem("课程表",R.drawable.courselist));
        data.add(new rv_frequentlyListItem("数学",R.drawable.math));
        data.add(new rv_frequentlyListItem("计算机",R.drawable.computer));
        data.add(new rv_frequentlyListItem("合唱",R.drawable.tutti));
        data.add(new rv_frequentlyListItem("动态",R.drawable.dynamic));

        Recommend.add(new rv_HomeResourceListItem("2021-05-01","浏览量100",R.drawable.picture,"语数外全国统一命题？选考科目等级赋分调整？"));
        Recommend.add(new rv_HomeResourceListItem("2021-05-01","浏览量100",R.drawable.picture,"语数外全国统一命题？选考科目等级赋分调整？"));
        Recommend.add(new rv_HomeResourceListItem("2021-05-01","浏览量100",R.drawable.picture,"语数外全国统一命题？选考科目等级赋分调整？"));

    }

}